import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { User } from '../../user/entities/user.entity';

@Entity()
export class Message {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 100 })
  title: string;

  @Column({ type: 'text' })
  content: string;

  @Column({ default: 1 })
  type: number; // 1: 系统消息, 2: 交易消息, 3: 聊天消息

  @Column({ default: false })
  isRead: boolean;

  @ManyToOne(() => User, (user) => user.messages)
  user: User;

  @ManyToOne(() => User, { nullable: true })
  fromUser: User;

  @CreateDateColumn()
  createTime: Date;
}
